/**
 * Jabber Public Methods
 */


//(function (w ) {
    
    function incomingAnswerClick(){
        var videodirection = true; //$('#videocall').is(':checked');
        var $call = w(this).parent().parent();
        var answerObject = $call.data('cwic');
        if (videodirection) {
            answerObject.videoDirection = 'SendRecv';
        } else {
            answerObject.videoDirection = (w(document).cwic('about').capabilities.video ? 'RecvOnly' : 'Inactive');
        }
        answerObject.remoteVideoWindow = 'videocallobject';
        $call.cwic('startConversation', answerObject);
    };

    function incomingDivertClick(){
         var $call = w(this).parent().parent();
         $call.cwic('endConversation',true);
    };
    function handleConversationUpdate(event, conversation, container) {
        settings.log('conversationUpdate Event for conversation:'+conversation.callId+' on Dom node: ' + event.target.id, conversation);
        calls.addCall(conversation, container);
        updateConversationInfo(conversation, $('#callcontainer'));
    };
    function handleConversationEnd(event, conversation) {
        //$('#callcontainer').hide();
        calls.removeCall(conversation.callId);

        settings.log('conversationEnd Event for conversation:'+conversation.callId);
        delayedVideoConversation = null;
        if (calls.isCallListEmpty()){
            calls.removeExternalVideoTitle();
            $(document).cwic('hideExternalWindow');
            //$('#closeexternalwindow').attr('disabled', false);
            //$('#externalpreview').attr('disabled', false);
        } else {
            calls.setExternalVideolTitle();
        }
    };
    
    function getCwicClasses(el) {
        var classes = jQuery(el).attr('class');
        var classestoadd = [];
        if(classes) {
            classes = classes.split(' ');
            for(var i=0;i<classes.length;i++) {
                if(classes[i].substring(4,0) === 'cwic') {
                    classestoadd.push(classes[i]);
                }
            }
        }
        return classestoadd.join(' ');
    }


//}( jQuery ));